﻿using System;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace QuickUIT.Tests
{
    [TestClass]
    public class AutomationConfigurationTests
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))] 
        public void ShouldThrowArgumentExceptionForNegativeWindowWaitTime()
        {
            AutomationConfiguration.Current.WindowWaitTime = -1; 
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))] 
        public void ShouldThrowArgumentExceptionForNegativeObjectSearchTime()
        {
            AutomationConfiguration.Current.ObjectSearchTime = -1;
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ShouldThrowArgumentNullExceptionForNullTreeWalker()
        {
            AutomationConfiguration.Current.TreeWalker = null; 
        }

        [TestMethod]
        public void ShouldGetSetWindowWaitTime()
        {
            Assert.AreEqual(30000, AutomationConfiguration.Current.WindowWaitTime);
            AutomationConfiguration.Current.WindowWaitTime = 1000;
            Assert.AreEqual(1000, AutomationConfiguration.Current.WindowWaitTime);
        }

        [TestMethod]
        public void ShouldGetSetObjectSearchTime()
        {
            Assert.AreEqual(30000, AutomationConfiguration.Current.ObjectSearchTime);
            AutomationConfiguration.Current.ObjectSearchTime = 1000;
            Assert.AreEqual(1000, AutomationConfiguration.Current.ObjectSearchTime);
        }

        [TestMethod]
        public void ShouldGetSetTreeWalker()
        {
            Assert.AreEqual(TreeWalker.RawViewWalker, AutomationConfiguration.Current.TreeWalker);
            AutomationConfiguration.Current.TreeWalker = TreeWalker.ControlViewWalker; 
            Assert.AreEqual(TreeWalker.ControlViewWalker, AutomationConfiguration.Current.TreeWalker);
        }

        [TestMethod]
        public void ShouldResetConfiguration()
        {
            AutomationConfiguration.Current.ObjectSearchTime = 1000;
            AutomationConfiguration.Current.WindowWaitTime = 1000;
            AutomationConfiguration.Current.TreeWalker = TreeWalker.ControlViewWalker; 
            Assert.AreEqual(1000, AutomationConfiguration.Current.ObjectSearchTime);
            Assert.AreEqual(1000, AutomationConfiguration.Current.WindowWaitTime);
            Assert.AreEqual(TreeWalker.ControlViewWalker, AutomationConfiguration.Current.TreeWalker);

            AutomationConfiguration.Current.Reset();

            Assert.AreEqual(30000, AutomationConfiguration.Current.ObjectSearchTime);
            Assert.AreEqual(30000, AutomationConfiguration.Current.WindowWaitTime);
            Assert.AreEqual(TreeWalker.RawViewWalker, AutomationConfiguration.Current.TreeWalker);
        }

        [TestCleanup]
        public void Cleanup()
        {
            AutomationConfiguration.Current.Reset();
        }
    }
}
